﻿using BaseDll;
using CommonTools;
using MotionIoLib;
using System;
using System.Windows.Forms;

namespace StationDemo
{
    public class Param_治具
    {
    }

    public class Point_治具
    {
        public PointInfo 标定起始位 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置1 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置2 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置3 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置4 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置5 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置6 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置7 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置8 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
        public PointInfo 测试位置9 = new PointInfo(0, 0, 0, 0, 0, 0, UserRight.Operator, "综合");
    }

    public class Config_治具
    {
    }

    public class Station_治具 : CommonTools.StationbaseEx<Param_治具, Point_治具, Config_治具>
    {
        public Station_治具(CommonTools.Stationbase station, Param_治具 param, Point_治具 point, Config_治具 config) : base(station, param, point, config)
        {

        }

        public enum StationStep
        {
        }




        #region 主流程
        protected override void StationWork(int step)
        {
        }

        protected override bool InitStation()
        {
            return true;
        }
        #endregion



        public override void StopDeal()
        {
        }

        public bool Function_气缸复位()
        {
            return true;
        }

        public bool Function_工站回零()
        {
            bool bResult = true;

            if (Name.Contains("A"))
            {
                UserDefineFunction.Axis_回零(this.AxisZ, "鱼眼箱Z轴", this);
                UserDefineFunction.Axis_回零(this.AxisY, "增距镜Y轴", this);
                UserDefineFunction.Axis_回零(this.AxisTy, "图卡Y轴", this);
                UserDefineFunction.Axis_回零(this.AxisX, "图卡U轴", this);
            }

            UserDefineFunction.Axis_回零(this.AxisU, "U轴", this);
            UserDefineFunction.Axis_回零(this.AxisTx, "Tx轴", this);
            return bResult;
        }

        public bool Function_运动到指定点位(int index, bool bmanual = false)
        {
            try
            {
                switch (index)
                {
                    case 0:
                        MoveMulitAxisPosWaitInpos(
                            new int[] { AxisU, AxisTx, AxisZ, AxisY, AxisTy },
                            new double[] { station_Point.标定起始位.pointU, station_Point.标定起始位.pointTx, station_Point.标定起始位.pointZ, station_Point.标定起始位.pointY, station_Point.标定起始位.pointTy },
                            new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High }, 0.5, bmanual, this);
                        return true;
                    case 1:
                        MoveMulitAxisPosWaitInpos(
                            new int[] { AxisU, AxisTx, AxisZ, AxisY, AxisTy },
                            new double[] { station_Point.测试位置1.pointU, station_Point.测试位置1.pointTx, station_Point.测试位置1.pointZ, station_Point.测试位置1.pointY, station_Point.测试位置1.pointTy },
                            new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High }, 0.5, bmanual, this); return true;
                    case 2:
                        MoveMulitAxisPosWaitInpos(
                           new int[] { AxisU, AxisTx, AxisZ, AxisY, AxisTy },
                           new double[] { station_Point.测试位置2.pointU, station_Point.测试位置2.pointTx, station_Point.测试位置2.pointZ, station_Point.测试位置2.pointY, station_Point.测试位置2.pointTy },
                           new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High }, 0.5, bmanual, this); return true;
                    case 3:
                        MoveMulitAxisPosWaitInpos(
                            new int[] { AxisU, AxisTx, AxisZ, AxisY, AxisTy },
                            new double[] { station_Point.测试位置3.pointU, station_Point.测试位置3.pointTx, station_Point.测试位置3.pointZ, station_Point.测试位置3.pointY, station_Point.测试位置3.pointTy },
                            new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High }, 0.5, bmanual, this); return true;
                    case 4:
                        MoveMulitAxisPosWaitInpos(
                            new int[] { AxisU, AxisTx, AxisZ, AxisY, AxisTy },
                            new double[] { station_Point.测试位置4.pointU, station_Point.测试位置4.pointTx, station_Point.测试位置4.pointZ, station_Point.测试位置4.pointY, station_Point.测试位置4.pointTy },
                            new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High }, 0.5, bmanual, this); return true;
                    default:
                        return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool Function_运动相对偏差(double cx, double cy, bool bmanual = false)
        {
            double posTX = MotionMgr.GetInstace().GetAxisActPos(AxisTx);
            posTX += cy;
            double posTZ = MotionMgr.GetInstace().GetAxisActPos(AxisU);
            posTZ += cx;
            MoveMulitAxisPosWaitInpos(
                           new int[] { AxisTx, AxisU },
                           new double[] { posTX, posTZ },
                           new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High }, 0.1, bmanual, this);

            return true;
        }

        public bool Function_GetPos(out double posTX, out double posTZ)
        {
            posTX = MotionMgr.GetInstace().GetAxisActPos(AxisTx);
            posTZ = MotionMgr.GetInstace().GetAxisActPos(AxisU);
            return true;
        }

        public bool Function_MoveTxTzPos(double posTX, double posTZ, bool bmanual = false)
        {
            MoveMulitAxisPosWaitInpos(
                           new int[] { AxisTx, AxisU },
                           new double[] { posTX, posTZ },
                           new double[] { (double)SpeedType.High, (double)SpeedType.High, (double)SpeedType.High }, 0.1, bmanual, this);
            return true;
        }


    }
}
